﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Shapes;
using DevExpress.Xpf.Core;
using ThanNhanTao.Server;
using ThanNhanTao.Server.BLL;
using ThanNhanTao.Server.Enum;
using ThanNhanTao.Server.Entities;
using DevExpress.Xpf.Printing;
using ThanNhanTao.Report;
using ThanNhanTao.CommonControl;


namespace ThanNhanTao
{
    /// <summary>
    /// Interaction logic for frmThongKeTongBNChayThan.xaml
    /// </summary>
    public partial class frmThongKeDanhSachDeNghiThanhToanMau25A : DXWindow
    {
        #region Fields

        PhieuBenhNhanBll phieuBenhNhanBLL;

        #endregion
        
        public frmThongKeDanhSachDeNghiThanhToanMau25A()
        {
            InitializeComponent();
            phieuBenhNhanBLL = new PhieuBenhNhanBll();
            calendar.rdbTheoNgay.IsEnabled = false;
            calendar.rdbTheoQuy.IsEnabled = false;
            calendar.rdbTheoThang.IsChecked = true;
            deNgayThongKe.EditValue = DateTime.UtcNow;
        }

        private void btnDong_Click(object sender, RoutedEventArgs e)
        {
            this.Close();
        }

        private void btnThongKe_Click(object sender, RoutedEventArgs e)
        {
            try
            {
                decimal tongCongTienXN;
                decimal tongCongTienThuoc;
                decimal tongCongTienMau;
                decimal tongCongTienPTTT;
                decimal tongCongTongCong;
                decimal tongCongTienBenhNhanChiTra;
                decimal tongCongTienDeNghiBHYTThanhToan;
                List<BenhNhanEntities> listBenhNhan = phieuBenhNhanBLL.ThongKeDeNghiThanhToanChiPhiKhamChuaBenhMau25A(calendar.StartDate, calendar.EndDate, cbThongKe.SelectedIndex == 0
                                                                                                    , out tongCongTienXN, out tongCongTienThuoc, out tongCongTienMau
                                                                                                    , out tongCongTienPTTT, out tongCongTongCong, out tongCongTienBenhNhanChiTra
                                                                                                    , out tongCongTienDeNghiBHYTThanhToan);
                rptDanhSachDeNghiThanhToanMau25A report = new rptDanhSachDeNghiThanhToanMau25A();
                report.DataSource = listBenhNhan;
                // Thống kê mặc định là thống kê BHYT cbThongKe.SelectedIndex == 0. Trường hợp = 1 là thống kê Viện phí
                report.BindHeader(calendar.StartDate.ToString("MM-yyyy"), cbThongKe.SelectedIndex == 0);
                report.BindDetails();
                report.BindGroupFooter(tongCongTienXN, tongCongTienThuoc, tongCongTienMau, tongCongTienPTTT, tongCongTongCong
                                        , tongCongTienBenhNhanChiTra, tongCongTienDeNghiBHYTThanhToan);
                DateTime? ngayThongKe = null;
                if (!string.IsNullOrEmpty(deNgayThongKe.DisplayText))
                    ngayThongKe = Convert.ToDateTime(deNgayThongKe.EditValue);
                report.BindFooter(ngayThongKe);
                XtraReportPreviewModel model = new XtraReportPreviewModel(report);
                documentPreview1.Model = model;
                model.Report.CreateDocument(false);
                
            }
            catch (Exception)
            {
                DXMessageBox.Show("Thống kê không thành công", "Thông báo", MessageBoxButton.OK, MessageBoxImage.Error);
            }
        }
    }
}
